package com.example;

import java.util.Date;

public class Book implements Comparable<Book> {
    private String bookName;
    private Date publish;

    public Book(String bookName, Date publish) {
        this.bookName = bookName;
        this.publish = publish;
    }

    public String getBookName() {
        return bookName;
    }

    public void setBookName(String bookName) {
        this.bookName = bookName;
    }

    public Date getPublish() {
        return publish;
    }

    public void setPublish(Date publish) {
        this.publish = publish;
    }

    @Override
    public String toString() {
        return "Book{" +
                "bookName='" + bookName + '\'' +
                ", publish=" + publish +
                '}';
    }

    /* 根据返回的数值来判断哪个大 */
    @Override
    public int compareTo(Book book) {
//        long time = publish.getTime() - book.getPublish().getTime();
//        if (time > 0) {
//            System.out.println("当前大");
//            return 1; // 当前比目标大
//        } else if (time < 0) {
//            System.out.println("当前小");
//            return -1; // 当前比目标小
//        } else {
//            System.out.println("当前与目标一样");
//            return 0; // 当前和目标相等
//        }
        /* 正数：当前大；0：相等；负数：当前小 */
        return -publish.compareTo(book.getPublish());
    }
}
